﻿<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="registerTitle" ContentPlaceHolderID="TitleContent" runat="server">
    <%= ViewStrings.LogOnStrings.RegisterHeader %>
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <script src="/Scripts/jquery.form.plugin/jquery.form.js" type="text/javascript"></script>
    <script src="/Scripts/jquery-validate/jquery.validate.min.js" type="text/javascript"></script>
    <script language="javascript" type="text/javascript">
    	$.validator.methods.equal = function(value, element, param) {
		return value == param;
	};


$(document).ready(function() {
   validateAccount();   
});

        var validator = null;

        function validateAccount() {

            validator = $("#regForm").validate({
                rules: {
                    username: {
                        required: true,
                    },
                    email: {
                      	required: true,
                      	email: true
                      },
                      password: {
                      	required: true,
                      	rangelength: [6, 24]
                      },
                      confirmPassword: {
                      	required: true,
                		rangelength: [6, 24],
                		equalTo: "#password"
                      },
                },
                messages: {
                    username: {
                        required: <%= string.Format("\"{0}\"",ViewStrings.LogOnStrings.UsernameRequired) %>,
                    },
                     email: {
                        required: <%= string.Format("\"{0}\"",ViewStrings.LogOnStrings.EmailRequired) %>,
                        email: <%= string.Format("\"{0}\"",ViewStrings.LogOnStrings.EmailFormatShouldBeCorrect) %>
                      },
                      password: {
                      	required: <%= string.Format("\"{0}\"",ViewStrings.LogOnStrings.PasswordRequired) %>,
                		rangelength: <%= string.Format("\"{0}\"",ViewStrings.LogOnStrings.PasswordLengthRequired) %>
                      },
                      confirmPassword: {
                      	required: <%= string.Format("\"{0}\"",ViewStrings.LogOnStrings.PassConfirmationMatchFailed) %>,
                		rangelength: <%= string.Format("\"{0}\"",ViewStrings.LogOnStrings.PasswordLengthRequired) %>,
                		equalTo: <%= string.Format("\"{0}\"",ViewStrings.LogOnStrings.PassConfirmationMatchFailed) %>
                      },

                },
                errorPlacement: function (error, element) {
                    var elementId = element.attr('id');

                    var valueContainerId = null;
                    if (elementId == 'username')
                        valueContainerId = 'usernameError';
                    else if (elementId == 'email')
                        valueContainerId = 'emailError';
                    else if (elementId == 'password')
                        valueContainerId = 'passwordError';
                    else if (elementId == 'confirmPassword')
                        valueContainerId = 'confirmPasswordError';
                    else
                        valueContainerId = 'generalError';

                    $('#' + valueContainerId).append(error);
                    }
                },
                submitHandler: function (form) {
                    var options = {
                        type: 'post',
                        dataType: 'json',
                        success: eventCreationSuccess,
                        error: eventCreationError
                    };

                    $(form).ajaxSubmit(options);
                }
            });
        }
    </script>
</asp:Content>
<asp:Content ID="registerContent" ContentPlaceHolderID="MainContent" runat="server">
    <div class="new_sob">
        <h2>
            <%= ViewStrings.LogOnStrings.Registration %></h2>
        <%= Html.ValidationSummary(ViewStrings.LogOnStrings.RegisterError) %>
        <form name="regForm" id="regForm" method="post" class="sob">
        <p>
            <label for="name">
                <%= ViewStrings.LogOnStrings.Username%>:
            </label>
            <%= Html.TextBox("username", null, new { size="25", maxlength="100" })%>
            <%= Html.ValidationMessage("username")%>
        </p>
        <p id="nameError"></p>
        <p>
            <label for="email">
                E-mail:
            </label>
            <%= Html.TextBox("email", null, new { size="25", maxlength="100" })%>
            <%= Html.ValidationMessage("email")%>
        </p>
        <p id="emailError"></p>
        <p>
            <label for="password">
                <%= ViewStrings.LogOnStrings.Password%>:
            </label>
            <%= Html.Password("password", null, new {  size="25", maxlength="100" })%>
            <%= Html.ValidationMessage("password")%>
            <span id="password_error"></span>
        </p>
        <p id="passwordError"></p>
        <p>
            <label for="confirmPassword">
                <%= ViewStrings.LogOnStrings.PasswordConfirm%>:
            </label>
            <%= Html.Password("confirmPassword", null, new { size="25", maxlength="100" })%>
            <%= Html.ValidationMessage("confirmPassword") %>
        </p>
        <p id="confirmPasswordError"></p>
        <p>
            <label for="language">
                <%= ViewStrings.LogOnStrings.Language%>:
            </label>
            <%= Html.DropDownList("language", new SelectList(WebGuiMvc.Models.Languages.All, "Value", "Key", null))%>
        </p>
        <p id="generalError"></p>
        <p>
            <input type="submit" id="submit" name="submit" value="<%= ViewStrings.LogOnStrings.Register %>" />
        </p>
        </form>
    </div>
</asp:Content>
